package test.service.contacts;

import java.util.ArrayList;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;

public class ContentProviderInfoGetter {
	private ContentResolver m_ContentResolver;
	private Uri testUri = testAppListContentProvider.CONTENT_URI;
	ContentProviderInfoGetter(ContentResolver cr){
		m_ContentResolver = cr;
	}
	
	public ArrayList<String> getAPPList(){
		ArrayList<String> rtContactsList = new ArrayList<String>();
		Cursor ListCursor = m_ContentResolver.query(
				testUri, 
				null, 
				null, 
				null, 
				null);
		if(ListCursor != null){
			if(ListCursor.moveToFirst()){
				for (int i = 0 ; ListCursor.getCount() > i ; i++){
					rtContactsList.add(ListCursor.getString(1));
					ListCursor.moveToNext();
				}
				return rtContactsList;
			}
			else
				return null;
		}
		return null;
		
	}
	
	public int addAPP(String name, String isenable){
		if(name.length() != 0){
			ContentValues contactValue = new ContentValues();
			contactValue.put(testAppListContentProvider.APP_NAME, name);
			contactValue.put(testAppListContentProvider.IS_ENABLE, isenable);
			
			Uri InsertResultUri = m_ContentResolver.insert(testUri, contactValue);
			
			return (int)ContentUris.parseId(InsertResultUri);
		}
		return -1;
	}
}
